<?php

namespace app\logic\api;

class L_setting
{
    /**
     * 创建资源
     * @param string $paramObj
     */
    public function store($paramObj=""){
        $dataObj = paramsObj();
        $dataObj->request = paramsObj();
        $dataObj->data = paramsObj();
        $dataObj->data->use_trans = false;

        $final_arr = logInit();
        if ($final_arr["error_no"] == 0) {
            $mixed = parseToArr($paramObj, "mixed", 0);
            $params = parseToArr($paramObj, "params", array());
            $messages = parseToArr($paramObj, "messages", array());
            $rules = array(
                'op' => 'require',
                'pid' => 'require',
            );
            $paramsObj = paramsObj();
            $paramsObj->params = $params;
            $paramsObj->mixed = $mixed;
            $paramsObj->rules = $rules;
            $paramsObj->messages = $messages;
            $checkResult = app("verifyParam")::validatorRequest($paramsObj);
            if ($checkResult["error_no"] == 0) {
                $dataObj->request = $checkResult["result"];
            } else {
                $final_arr = logCallErrorMsg($final_arr, $checkResult);
            }
        }
        if ($final_arr["error_no"] == 0) {
            if($dataObj->request->op=="random"){
                if($final_arr["error_no"]==0) {
                    //先删除
                    $paramsObj = paramsObj();
                    $paramsObj->params = array(
                        "pid" => $dataObj->request->pid,
                        "itemKey" => "random",
                    );
                    $checkResult = app("S_Admin_setting")->deleteByKey($paramsObj);
                    if ($checkResult["error_no"] == 0) {

                    } else {
                        $final_arr = logCallErrorMsg($final_arr, $checkResult);
                    }
                }
                if($final_arr["error_no"]==0) {
                    $paramsObj=paramsObj();
                    $paramsObj->params=array(
                        'itemKey' => 'random',
                        'itemValue' => time(),
                        'pid' => $dataObj->request->pid,
                    );
                    $checkResult=app("L_Admin_setting")->store($paramsObj);
                    if ($checkResult["error_no"] == 0) {

                    } else {
                        $final_arr = logCallErrorMsg($final_arr, $checkResult);
                    }
                }
            }
        }
        return $final_arr;
    }

    public function __call($name,$arguments)
    {
        return recordLogMsgLevelTwo(app("errorLevel")::E_WARNING,app("errorCode")::UNDEFINED_METHOD,lang("sys.noMethodDefined"),$name,$arguments);
    }
}